import time

from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.wait import WebDriverWait


class Base:
    def __init__(self, driver,url):
        self.driver = driver
        self.driver.get(url)
        self.driver.maximize_window()
    #寻找元素
    def __element_find_element(self,locator) -> WebElement:
        return WebDriverWait(self.driver, 10).until(lambda x: x.find_element(*locator))

    #输入文本
    def input_text(self,locator,text):
        self.__element_find_element(locator).send_keys(text)
        time.sleep(2)

    #获取文本
    def get_text(self,locator):
        return self.__element_find_element(locator).text
    #点击按钮

    def click_text(self,locator):
        self.__element_find_element(locator).click()

    #获取当前页面的url
    def get_current_url(self):
        return self.driver.current_url
    #关闭驱动
    def close(self):
        self.driver.quit()